package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.dto.DeviceDto;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品设备Controller
 *
 * @author ruoyi
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "产品设备相关接口")
public class DeviceController extends BaseController {
    @Autowired
    private IDeviceService deviceService;


    /**
     * 同步互联网产品
     *
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation(value = "从物联网平台同步产品列表")
    public R ductList() {
        deviceService.ductList();
        return R.ok();
    }

    @GetMapping("/allProduct")
    @ApiOperation(value = "查询所有产品列表")
    public R<List<ProductVo>> allProduct() {
        return R.ok(this.deviceService.allProduct());
    }

    /**
     * 4、分页查询设备列表
     *
     * @param device
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分页查询设备列表")
    public TableDataInfo<Device> list(Device device) {
        startPage();
        List<Device> list = this.deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    @PostMapping("/register")
    @ApiOperation("注册设备")
    public R register(@RequestBody DeviceDto deviceDto) {
        deviceService.saveRegister(deviceDto);
        return R.ok();
    }

}
